﻿using System;
using System.Linq;
using System.Text;
using Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EntityFramework
{
    [TestClass]
    public class Graduation
    {
        [TestMethod]
        public void TestNewEmployee()
        {
            DatabaseSetup.SetupGraduation();
            Console.WriteLine(Change());
        }


        private String Change()
        {
            string dr = "Dr. ";
            string sir = "Sir ";
            IQueryable<Employee> employees = null;
            using (var db = new EntityFrameworkDemoEntities())
            {
                employees = (from e in db.Events
                             where new[] {"Graduation", "Kighthood"}.Contains(e.EventTitle)
                             select e.Employee1);

                foreach (Employee employee in employees)
                {
                    if (employee.Events.Any(e => e.EventTitle == "Kighthood"))
                    {
                        employee.Name = sir + employee.Name;
                    }
                    else if (employee.Events.Any(e => e.EventTitle == "Graduation"))
                    {
                        employee.Name = dr + employee.Name;
                    }
                }
                db.SaveChanges();
                var output = new StringBuilder();
                output.AppendLine("changed the names of:");
                foreach (Employee employee in employees)
                {
                    output.AppendLine(employee.Name);
                }
                return output.ToString();
            }
        }
    }
}